﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics.CodeAnalysis;
using ZR.Admin.WebApi.Extensions;
using ZR.Model.mes.md;
using ZR.Service.mes.md;
using ZR.Service.mes.md.IService;

namespace ZR.Admin.WebApi.Controllers.mes.md
{
    [Route("mes/md/workproroute")]
    public class MdTechnologicalProrouteController : BaseController
    {
        IMdTechnologicalProrouteService workproroute;

        public MdTechnologicalProrouteController(IMdTechnologicalProrouteService workproroute)
        {
            this.workproroute = workproroute;
        }
      
        [HttpGet("list")]
        public IActionResult List(int pageNum, int pageSize, string ProrouteCode="", string ProrouteName="")
        {

            (int, List<MdTechnologicalProroute>) data = workproroute.GetAll(ProrouteCode, ProrouteName, pageNum, pageSize);

            return ToResponse(new ApiResult(200, "success", data));

        }


        /// <summary>
        /// 插入车间
        /// </summary>
        /// <param name="workshop"></param>
        /// <returns></returns>
        [HttpPost("addProcess")]
        public IActionResult AddWorkshop([FromBody] MdTechnologicalProroute workshop)
        {
            if (workshop != null)
                workshop.ToCreate(HttpContext);
            int result = workproroute.AddWorkProroute(workshop);
            return SUCCESS(result);
        }


        [HttpPost("updateProcess")]
        public IActionResult UpdateWorkshop([FromBody] MdTechnologicalProroute workshop)
        {
            if (workshop != null)
                workshop.ToUpdate(HttpContext);
            int result = workproroute.UpdateWorkProroute(workshop);
            return SUCCESS(result);
        }


        [HttpPost("delProcess")]
        public IActionResult deleteWorkshop([FromBody] List<int> ids)
        {
            if (ids != null)
            {
                int result = workproroute.deleteWorksProroute(ids.ToArray());
                return ToResponse(result);
            }
            return null;
        }




    }
}


